package c.c.b.a.a;

import java.io.IOException;

/* compiled from: AsyncTimeout */
public class a implements v {
    public final /* synthetic */ v a;
    public final /* synthetic */ c b;

    public a(c cVar, v vVar) {
        this.b = cVar;
        this.a = vVar;
    }

    public x a() {
        return this.b;
    }

    public void close() throws IOException {
        this.b.h();
        try {
            this.a.close();
            this.b.i(true);
        } catch (IOException e) {
            IOException e2 = e;
            c cVar = this.b;
            if (cVar.l()) {
                e2 = cVar.k(e2);
            }
            throw e2;
        } catch (Throwable th) {
            this.b.i(false);
        }
    }

    public void flush() throws IOException {
        this.b.h();
        try {
            this.a.flush();
            this.b.i(true);
        } catch (IOException e) {
            IOException e2 = e;
            c cVar = this.b;
            if (cVar.l()) {
                e2 = cVar.k(e2);
            }
            throw e2;
        } catch (Throwable th) {
            this.b.i(false);
        }
    }

    public void g0(e eVar, long j) throws IOException {
        y.a(eVar.b, 0, j);
        while (true) {
            long j2 = 0;
            if (j > 0) {
                s sVar = eVar.a;
                while (j2 < 65536) {
                    j2 += (long) (sVar.c - sVar.b);
                    if (j2 >= j) {
                        j2 = j;
                        break;
                    }
                    sVar = sVar.f;
                }
                this.b.h();
                try {
                    this.a.g0(eVar, j2);
                    j -= j2;
                    this.b.i(true);
                } catch (IOException e) {
                    IOException e2 = e;
                    c cVar = this.b;
                    if (cVar.l()) {
                        e2 = cVar.k(e2);
                    }
                    throw e2;
                } catch (Throwable th) {
                    this.b.i(false);
                }
            } else {
                return;
            }
        }
    }

    public String toString() {
        StringBuilder g = c.b.a.a.a.g("AsyncTimeout.sink(");
        g.append(this.a);
        g.append(")");
        return g.toString();
    }
}
